<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>DB-&gt;join()</title>
    <link rel="stylesheet" href="apiReference.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Berkeley DB C API Reference" />
    <link rel="up" href="db.html" title="Chapter 2.  The DB Handle" />
    <link rel="prev" href="dbget_type.html" title="DB-&gt;get_type()" />
    <link rel="next" href="dbkey_range.html" title="DB-&gt;key_range()" />
  </head>
  <body>
    <div xmlns="" class="navheader">
      <div class="libver">
        <p>Library Version 12.1.6.2</p>
      </div>
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">DB-&gt;join()</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="dbget_type.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 2. 
                The DB Handle
        </th>
          <td width="20%" align="right"> <a accesskey="n" href="dbkey_range.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="dbjoin"></a>DB-&gt;join()</h2>
          </div>
        </div>
      </div>
      <pre class="programlisting">#include &lt;db.h&gt;

int
DB-&gt;join(DB *primary,
    DBC **curslist, DBC **dbcp, u_int32_t flags);  </pre>
      <p>
         The <code class="methodname">DB-&gt;join()</code> method creates a specialized join cursor for use in
         performing equality or natural joins on secondary indices.  For
         information on how to organize your data to use this functionality,
         see <a href="../../programmer_reference/am_cursor.html#am_join" class="olink">Equality join</a>.
    </p>
      <p>
             The <code class="methodname">DB-&gt;join()</code> method is called using the 
             <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a>  handle of the primary
             database.
    </p>
      <p>
         The join cursor supports only the <a class="xref" href="dbcget.html" title="DBcursor-&gt;get()">DBcursor-&gt;get()</a>  and 
         <a class="xref" href="dbcclose.html" title="DBcursor-&gt;close()">DBcursor-&gt;close()</a> cursor functions:
    </p>
      <div class="itemizedlist">
        <ul type="disc">
          <li>
            <p>
                        <span class="bold"><strong> <a class="xref" href="dbcget.html" title="DBcursor-&gt;get()">DBcursor-&gt;get()</a> </strong></span>
                </p>
            <p>
                         Iterates over the values associated with the keys to which each item
                         in <span class="bold"><strong>curslist</strong></span> was initialized.  Any
                         data value that appears in all items specified by the <span class="bold"><strong>curslist</strong></span> parameter is then used as a key into
                         the <span class="bold"><strong>primary</strong></span>, and the key/data pair
                         found in the <span class="bold"><strong>primary</strong></span> is returned. The
                         <span class="bold"><strong>flags</strong></span> parameter must be set to 0 or
                         the following value:  
                         
                 </p>
            <div class="itemizedlist">
              <ul type="circle">
                <li>
                  <p>
                                         <span class="bold"><strong><code class="literal">DB_JOIN_ITEM</code></strong></span>
                                 </p>
                  <p>
                                         Do not use the data value found in all the cursors as a lookup key for
                                         the <span class="bold"><strong>primary</strong></span>, but simply return it in
                                         the key parameter instead. The data parameter is left unchanged.
                                 </p>
                </li>
              </ul>
            </div>
            <p>
                         In addition, the following flag may be set by bitwise inclusively
                         <span class="bold"><strong>OR</strong></span>'ing it into the <span class="bold"><strong>flags</strong></span> parameter:  
                 </p>
            <div class="itemizedlist">
              <ul type="circle">
                <li>
                  <p>
                                         <span class="bold"><strong> <code class="literal">DB_READ_UNCOMMITTED</code></strong></span>
                                </p>
                  <p>
                                         Configure a transactional join operation to have degree 1 isolation,
                                         reading modified but not yet committed data.  Silently ignored if the
                                         <a class="link" href="dbopen.html#dbopen_DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> 
                                         flag was not specified when the underlying database was opened.
                                </p>
                </li>
                <li>
                  <p>
                                         <span class="bold"><strong><code class="literal">DB_RMW</code></strong></span>
                                </p>
                  <p>
                                         Acquire write locks instead of read locks when doing the read, if
                                         locking is configured.  Setting this flag can eliminate deadlock
                                         during a read-modify-write cycle by acquiring the write lock during
                                         the read part of the cycle so that another thread of control acquiring
                                         a read lock for the same item, in its own read-modify-write cycle,
                                         will not result in deadlock.
                                 </p>
                </li>
              </ul>
            </div>
          </li>
          <li>
            <p>
                        <span class="bold"><strong> <a class="xref" href="dbcclose.html" title="DBcursor-&gt;close()">DBcursor-&gt;close()</a> </strong></span>
                     </p>
            <p>
                          Close the returned cursor and release all resources.  (Closing the
                          cursors in <span class="bold"><strong>curslist</strong></span> is the
                          responsibility of the caller.)
                      </p>
          </li>
        </ul>
      </div>
      <p>
          The <code class="methodname">DB-&gt;join()</code> method can not be used
          with a sliced database.
      </p>
      <p>
          The <code class="methodname">DB-&gt;join()</code> <span>
            <span>
                  method returns a non-zero error value on failure and 0 on success.
            </span>
            
        </span>
      </p>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="idm140711186702240"></a>Parameters</h3>
            </div>
          </div>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="idm140711186697248"></a>curslist</h4>
              </div>
            </div>
          </div>
          <p>
                          The <span class="bold"><strong>curslist</strong></span> parameter contains a
                          NULL terminated array of cursors. Each cursor must have been
                          initialized to refer to the key on which the underlying database
                          should be joined.  Typically, this initialization is done by a 
                          <a class="xref" href="dbcget.html" title="DBcursor-&gt;get()">DBcursor-&gt;get()</a>  call with the
                          <a class="link" href="dbcget.html#dbcget_DB_SET">DB_SET</a>  flag
                          specified.  Once the cursors have been passed as part of a <span class="bold"><strong>curslist</strong></span>, they should not be accessed or
                          modified until the newly created join cursor has been closed, or else
                          inconsistent results may be returned.
                     </p>
          <p>
                          Joined values are retrieved by doing a sequential iteration over the
                          first cursor in the <span class="bold"><strong>curslist</strong></span>
                          parameter, and a nested iteration over each secondary cursor in the
                          order they are specified in the <span class="bold"><strong>curslist</strong></span> parameter.  This requires database
                          traversals to search for the current datum in all the cursors after
                          the first.  For this reason, the best join performance normally
                          results from sorting the cursors from the one that refers to the least
                          number of data items to the one that refers to the most.  By default,
                          <code class="methodname">DB-&gt;join()</code> does this sort on behalf of its caller.
                     </p>
          <p>
                          For the returned join cursor to be used in a transaction-protected
                          manner, the cursors listed in <span class="bold"><strong>curslist</strong></span> must have been created within the
                          context of the same transaction.
                     </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="idm140711187057104"></a>dbcp</h4>
              </div>
            </div>
          </div>
          <p>
                          The newly created join cursor is returned in the memory location to
                          which <span class="bold"><strong>dbcp</strong></span> refers.
                     </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="idm140711187902976"></a>flags</h4>
              </div>
            </div>
          </div>
          <p>
                          The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
                          or the following value:
                     </p>
          <div class="itemizedlist">
            <ul type="disc">
              <li>
                <p><a id="join_DB_JOIN_NOSORT"></a>
                                <code class="literal">DB_JOIN_NOSORT</code>
                            </p>
                <p>
                                Do not sort the cursors based on the number of data items to which
                                they refer.  If the data are structured so that cursors with many data
                                items also share many common elements, higher performance will result
                                from listing those cursors before cursors with fewer data items; that
                                is, a sort order other than the default.  The DB_JOIN_NOSORT flag
                                permits applications to perform join optimization prior to calling the
                                <code class="methodname">DB-&gt;join()</code> method.
                            </p>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="idm140711186981760"></a>Errors</h3>
            </div>
          </div>
        </div>
        <p>
                         The <code class="methodname">DB-&gt;join()</code> <span>
            <span>
                 method may fail and return one of the following non-zero errors:
            </span>
            
        </span>
                    </p>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="idm140711188720688"></a>  DB_REP_HANDLE_DEAD</h4>
              </div>
            </div>
          </div>
          <p>
                When a client synchronizes with the master, it is possible for committed
                transactions to be rolled back. This invalidates all  the database and cursor
                handles opened in the replication environment. Once this occurs, an attempt to use
                such a handle will 
                
                return <code class="literal">DB_REP_HANDLE_DEAD</code>.
                The application will need to discard the handle and open a new one in order to
                continue processing.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="idm140711188600112"></a>DB_REP_LOCKOUT</h4>
              </div>
            </div>
          </div>
          <p>
                The operation was blocked by client/master synchronization.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="idm140711188784448"></a>DB_SECONDARY_BAD</h4>
              </div>
            </div>
          </div>
          <p>
                A secondary index references a nonexistent primary key.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="idm140711189328848"></a>EINVAL</h4>
              </div>
            </div>
          </div>
          <p>
                          If cursor methods other than  <a class="xref" href="dbcget.html" title="DBcursor-&gt;get()">DBcursor-&gt;get()</a>  
                          or <a class="xref" href="dbcclose.html" title="DBcursor-&gt;close()">DBcursor-&gt;close()</a>  were called;
                          if this method is called on a sliced database; 
                          or if an invalid flag value or parameter was specified.
                        </p>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="idm140711187918928"></a>Class</h3>
            </div>
          </div>
        </div>
        <p>
                    <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a>  
            </p>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="idm140711190337152"></a>See Also</h3>
            </div>
          </div>
        </div>
        <p>
                     <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 
                </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="dbget_type.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="db.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="dbkey_range.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">DB-&gt;get_type() </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> DB-&gt;key_range()</td>
        </tr>
      </table>
    </div>
  </body>
</html>
